package com.example.myapplication;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewPropertyAnimator;
import android.widget.Button;
import android.widget.ImageView;

/**
 * 组合动画
 * Created by Lx on 2018/12/20.
 */

public class AnimatorSetActivity extends AppCompatActivity implements View.OnClickListener {
    Button animatorSet, viewpropertyanimator;

    ImageView imageView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animatorset);
        init();
    }

    private void init() {
        animatorSet = findViewById(R.id.animatorSet_btn);
        imageView = findViewById(R.id.animatorset_img);
        viewpropertyanimator = findViewById(R.id.viewpropertyanimator_btn);

        animatorSet.setOnClickListener(this);
        viewpropertyanimator.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.animatorSet_btn:
//                AnimatorSet
//                AnimatorSet可以让几个动画同时执行，也可以设置执行顺序、延迟执行等
//                after(Animator anim)--将现有动画插入到传入的动画之后执行
//                after(long delay)--将现有动画延迟指定毫秒后执行
//                before(Animator anim)--将现有动画插入到传入的动画之前执行
//                with(Animator anim)--将现有动画和传入的动画同时执行
//                playSequentially(Animator... items)--依次执行

                ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(imageView, "scaleX", 1.0f, 2.5f, 1.0f);
                ObjectAnimator objectAnimator2 = ObjectAnimator.ofFloat(imageView, "scaleY", 1.0f, 2.5f, 1.0f);
                ObjectAnimator objectAnimator3 = ObjectAnimator.ofFloat(imageView, "rotationY", 0.0f,90.0f);
                AnimatorSet animatorSet = new AnimatorSet();
                animatorSet.play(objectAnimator1).with(objectAnimator2).with(objectAnimator3);
                animatorSet.setDuration(2000);
                animatorSet.start();


                break;
            case R.id.viewpropertyanimator_btn:
                ViewPropertyAnimator animator = imageView.animate();
                animator.translationX(200)
                        .scaleX(2)
                        .scaleY(2)
                        .setDuration(2000)
                        .start();

                break;
        }
    }
}
